home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 1.0 KB | 42 lines | [TEXT/ttxt] |
- --<<<
- -- Kaleida Labs, Inc.
- -- Field Guide to the ScriptX Language
- -- chapter 6, example 7
-
- -- create a module to avoid namespace conflicts
- module Scratch30 uses ScriptX end
- in module Scratch30
-
- -- take care of global declarations in this file
- global tryThisOut, i, myArrayOfIntegers
-
-
- -- examples of free method definitions
-
- -- add a method to an existing object
- tryThisOut := #(1,2)
- method appendSum self {object tryThisOut} n m ->
- (append self (n + m); return self)
-
- -- add a method to an existing scripted class
- class MyClass () end
- method jellydonut self {class MyClass} name ->
- format debug "%* is not a jellydonut!\n" name @Unadorned
-
- i := new myclass
- jellydonut i "cruller"
-
- -- define a sequence, then override the append method
- global myArrayOfIntegers := #()
-
- -- override the append method on myArrayOfIntegers
- method append self {object myArrayOfIntegers} item -> (
- if (getClass item = ImmediateInteger) then (
- nextMethod self item
- )
- else (
- format debug "Not an ImmediateInteger: %*\n" item @normal
- return undefined
- )
- )
- -->>>